package controllers;

import java.util.Date;

import models.User;
import play.Logger;
import play.i18n.Messages;
import play.mvc.Before;
import play.mvc.Controller;
import play.mvc.Scope.Session;
import utils.Paginate;
import utils.constants.SessionConstants;

import com.google.appengine.api.NamespaceManager;
import com.google.gson.JsonNull;

public class BaseController extends Controller {
	@Before
	static void addDefaults() {
		//String domain = Session.current().get(SessionConstants.DOMAIN);
		//NamespaceManager.set(domain);
		
		User user = getCurrentUser();
	    renderArgs.put("appTitle", Messages.get("app.title"));
	    renderArgs.put("user", user);
	    if(user != null && user.getProfile() != null && user.getProfile().getFirstName() != null) {
	    	Logger.debug("Add defaults: user -> " + user.getProfile().getFirstName());
	    } else {
	    	Logger.debug("Add defaults: user -> unkNown!");
	    }
	}

	public static User getCurrentUser() {
		return Security.getCurrentUser();
	}
	
	public static void error() {
		render("errors/error.html");
	}
	
	public static Date getCurrentDate() {
		return new Date(System.currentTimeMillis());
	}
	
	public static boolean isBlank(String s) {
		if(s == null || ("").equals(s)) return true;
		return false;
	}
	
	public static boolean isNull(Object o) {
		if(o == null || (new JsonNull()).equals(o)) return true;
		return false;
	}
}
